package com.imooc.base;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    //1. 定义交换机
    //2. 定义队列
    //3. 创建交换机
    //4. 创建队列
    //5. 绑定队列和交换机
    public static final String EXCHANGE_NAME = "exchange_msg";
    public static final String QUEUE_NAME = "queue_msg";
    @Bean(EXCHANGE_NAME)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).build();
    }
    @Bean(QUEUE_NAME)
    public Queue queue(){
        return new Queue(QUEUE_NAME);
    }
    @Bean
    public Binding binding(@Qualifier(EXCHANGE_NAME)Exchange exchange,
                           @Qualifier(QUEUE_NAME)Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("sys.msg.*").noargs();
    }
}
